-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Private Specification, Partial Struct Encoding, and Constructor #619
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First batch of comments.
The specifications need to be public. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More comments. I have not yet looked at the desugarer, the ConstructorEncoding, the AssignmentEncoding, and the DerefEncoding
src/main/scala/viper/gobra/frontend/info/ExternalTypeInfo.scala
Outdated
Show resolved
Hide resolved
src/main/scala/viper/gobra/translator/encodings/structs/StructEncoding.scala
Outdated
Show resolved
Hide resolved
src/main/scala/viper/gobra/translator/encodings/structs/StructEncoding.scala
Outdated
Show resolved
Hide resolved
case (loc: in.Location) :: ctx.CompleteStruct(_) / Shared => | ||
val deref = ctx.lookupDereference(loc.typ) | ||
if (deref.isEmpty) { sh.convertToExclusive(loc)(ctx, ex) } | ||
else { | ||
val (pos, info, errT) = loc.vprMeta | ||
val funcName = deref.getOrElse(null).uniqueName | ||
for { | ||
b <- bind(loc)(ctx) | ||
v = variable(ctx)(b).localVar | ||
func = vpr.FuncApp(funcName, Seq(v))(pos, info, v.typ, errT) | ||
} yield func | ||
} | ||
|
||
case (loc: in.Location) :: ctx.PartialStruct(_) / Shared => | ||
val deref = ctx.lookupDereference(loc.typ) | ||
if (deref.isEmpty) { sh.convertToExclusive(loc)(ctx, pex) } | ||
else { | ||
val (pos, info, errT) = loc.vprMeta | ||
val funcName = deref.getOrElse(null).uniqueName | ||
for { | ||
b <- bind(loc)(ctx) | ||
v = variable(ctx)(b).localVar | ||
func = vpr.FuncApp(funcName, Seq(v))(pos, info, v.typ, errT) | ||
} yield func | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected that for CompleteStruct it is always sh.convertToExclusive(...)
and for PartialStruct, it is always the call to the deref function (there is an error if there is no deref function).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we always use sh.convertToExclusive(...)
for a CompleteStruct, then this statement would fail:
requires acc(&a.Left) && acc(&a.Right) && a.PrivateMem()
func foo(a *Pair) {
x := *a // fails, not enough permission
}
Since there is no call to dereference, Pair
that has fields Left
, Right
, p
does not have access to the field p
(within the same package until we unfold a.PrivateMem()
). The constructor always gets called once defined, therefore:
x := &Pair{Left: 2, Right: 0, p: 1}
assert(x.PrivateMem()) //constructor ensures x.PrivateMem()
and the assignment y := *x
would fail, despite constructing x
just before.
The question is if we want to explicitly unfold x.PrivateMem() or just let the dereference handle it.
src/main/scala/viper/gobra/translator/encodings/structs/AssignmentsEncoding.scala
Outdated
Show resolved
Hide resolved
src/main/scala/viper/gobra/translator/encodings/structs/DereferenceEncoding.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More comments. I have not yet looked at the desugarer, the ConstructorEncoding, the AssignmentEncoding, and the DerefEncoding
are all valid expressions right now. There may be some bugs for pure functions and predicates because they are imported into other packages with the body.
c
and import it into another package:then it would be changed into
In the viper encoding a partial_struct removes an axiom from the Tuple Domain to disallow the comparison of two partial_structs.
In viper that means:
get changed to:
Please check the written code and if additional documentations are needed in some places. (Also there might be some small bits of a constructor, which is not finished yet.)